package com.qiangqiang.task.server.util;

import java.util.Random;

/**
 * @program: task
 * @description: 返回随机数，并根据概率、比率
 * @author: Sky.lin
 * @create: 2019-02-16 17:27
 **/
public class MathRandom {
    // [0,50) 的概率
    public static double rate1 = 0.65;
    // [50,100)
    public static double rate2 = 0.20;
    // [100,200)
    public static double rate3 = 0.10;
    // [200,250)
    public static double rate4 = 0.05;


    public static int percentageRandom() {
        Random random = new Random();
        double randomNumber = random.nextDouble();
        if (randomNumber >= 0 && randomNumber <= rate1)
            return random.nextInt(50);
        else if (randomNumber > rate1 && randomNumber <= rate1 + rate2)
            return random.nextInt(50) + 50;
        else if (randomNumber > rate1 + rate2 && randomNumber <= rate1 + rate2 + rate3)
            return random.nextInt(100) + 100;
        else
            return random.nextInt(50) + 200;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            System.out.println(percentageRandom());
        }
    }
}
